<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ page import="com.pizzaonline.utils.Utils" %>
<%@ page import="com.pizzaonline.JDBC.*" %>
<%@ page import="java.sql.*" %>

<%
	String status = (String)session.getAttribute("status");
	if (status == null || !status.equals("admin")) {
		Utils.rediriger(out, "index.jsp?err="+Utils.getErrorID("NoAccess"));
	} else {
		String id = request.getParameter("id");DataBase d = new DataBase();
		d.connexionBD();
		Connection c = d.getConnection();
		if (c == null) {
			Utils.rediriger(out, "admin.jsp?err="+Utils.getErrorID("SQLConnProb"));
		} else if (id != null) {
			ResultSet res = null;
			try {
				res = d.select("id_util,login,mdp,nom,prenom,tel,adresse,status", "utilisateur", "id_util='"+id+"'");
				if (res.first()) {
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd" />
<html>
<head>
<title>Modifier un utilisateur</title>
<link rel="stylesheet" type="text/css" href="css/admin.css" />
</head>
<body>

<h3 class="descr">Modifier les informations de l'utilisateur :</h3>
<form action="admin.jsp" method="post">
<ul>
  <li class="left">
    <ul>
      <li class="champ">id :</li>
      <li class="valeur">
        <input type="hidden" name="id_util_def" value="<%= res.getString("id_util") %>" />
        <input type="text" name="id_util" size="5" maxlength="20" value="<%= res.getString("id_util") %>" />
      </li>

      <li class="champ">login :</li>
      <li class="valeur">
        <input type="hidden" name="login_def" value="<%= res.getString("login") %>" />
        <input type="text" name="login" size="10" maxlength="10" value="<%= res.getString("login") %>" />
      </li>

      <li class="champ">password :</li>
      <li class="valeur">
        <input type="hidden" name="mdp_def" value="<%= res.getString("mdp") %>" />
      	<input type="text" name="mdp" size="10" maxlength="20" value="<%= res.getString("mdp") %>" />
      </li>

      <li class="champ">status :</li>
      <li class="valeur">
        <select name="status" size="1">
<%
					String st = res.getString("status");
					if (st.equals("client"))
%>
          <option<%= (st.equals("client")?" selected=\"selected\"":"") %>>client</option>
          <option<%= (st.equals("chef")?" selected=\"selected\"":"") %>>chef</option>
          <option<%= (st.equals("admin")?" selected=\"selected\"":"") %>>admin</option>
        </select>
        <input type="hidden" name="status_def" value="<%= st %>" />
      </li>
      <li class="champ">nom :</li>
      <li class="valeur">
        <input type="hidden" name="nom_def" value="<%= res.getString("nom") %>" />
        <input type="text" name="nom" size="10" maxlength="20" value="<%= res.getString("nom") %>" />
      </li>

      <li class="champ">prénom :</li>
      <li class="valeur">
        <input type="hidden" name="prenom_def" value="<%= res.getString("prenom") %>" />
        <input type="text" name="prenom" size="10" maxlength="20" value="<%= res.getString("prenom") %>" />
      </li>

      <li class="champ">téléphone :</li>
      <li class="valeur">
        <input type="hidden" name="tel_def" value="<%= res.getString("tel") %>" />
        <input type="text" name="tel" size="10" maxlength="10" value="<%= res.getString("tel") %>" />
      </li>

      <li class="champ">adresse :</li>
      <li class="valeur">
        <input type="hidden" name="adresse_def" value="<%= res.getString("adresse") %>" />
        <input type="text" name="adresse" size="10" maxlength="100" value="<%= res.getString("adresse") %>" />
      </li>
      <li style="clear:both;">
        <input type="hidden" name="form" value="modif" />
        <input type="submit" value="Modifier" />
      </li>
    </ul>
  </li>
</ul>
</form>
<%
				} else {
%>
  <h1>Il n'existe pas d'utilisateur ayant pour id <%= id %> !</h1>
<%
				}
			} catch (SQLException e) {
				out.print("DEBUG SQL ERROR : <br />" + e + "<br />");
			}
%>

<%
		} else {
%>
  <h1>L'id de l'utilisateur à traiter est nécessaire ici.</h1>
<%
		}
%>
</body>
</html>
<%
	}
%>